package com.ruoyi.ly.controller;


import com.ruoyi.ly.domain.dto.PageSpaceFloorDTO;
import com.ruoyi.ly.domain.dto.SpaceFloorAddDTO;
import com.ruoyi.ly.domain.dto.SpaceFloorUpdateDTO;
import com.ruoyi.ly.domain.vo.SpaceFloorVO;
import com.ruoyi.ly.service.SpaceFloorService;
import com.ruoyi.ly.utils.PageResult;
import com.ruoyi.ly.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;

@RestController
@RequestMapping("/floor")
@Api("楼层管理接口")
@Slf4j
public class SpaceFloorController {

    @Autowired
    private SpaceFloorService spaceFloorService;


    //  新增楼层信息
   @PostMapping("/add")
   @ApiOperation(value = "新增楼层信息")
    public Result<String> insert(@RequestBody SpaceFloorAddDTO spaceFloorDTO){
        log.info("新增楼层信息");
        spaceFloorService.save(spaceFloorDTO);
        return Result.success();
    }

    //分页查询
    @GetMapping("/page")
    @ApiOperation(value = "分页查询")
    public Result<PageResult> page(PageSpaceFloorDTO pageSpaceFloorDTO) {
        log.info("分页查询：{}", pageSpaceFloorDTO);
        PageResult pageResult = spaceFloorService.pageQuery(pageSpaceFloorDTO);
        return Result.success(pageResult);
    }

    //删除楼层
    @DeleteMapping("/delete/{floorId}")
    @ApiOperation(value = "删除楼层")
    public Result delete(@PathVariable("floorId")Long floorId) {
        log.info("删除楼层：{}", floorId);
        spaceFloorService.delete(floorId);
        return Result.success();
    }

    //修改楼层
    @PutMapping("/update")
    @ApiOperation(value = "修改楼层")
    public Result update(@RequestBody SpaceFloorUpdateDTO spaceFloorUpdateDto) {
        log.info("修改楼层：{}", spaceFloorUpdateDto);
        spaceFloorService.update(spaceFloorUpdateDto);
        return Result.success();
    }

    //根据楼层id查询楼层详情
    @GetMapping("/{floorId}")
    @ApiOperation(value = "根据楼层id查询楼层详情")
    public  Result<SpaceFloorVO> selectById(@PathVariable Long floorId) {
        log.info("根据楼层id查询楼层详情：{}",floorId);
        SpaceFloorVO spaceFloorVO = spaceFloorService.selectById(floorId);
        return Result.success(spaceFloorVO);
    }

    @GetMapping("/exportData")
    @ApiOperation(value = "导出数据")
    public void exportData(HttpServletResponse response){
       spaceFloorService.exportData(response);
    }
}
